package com.searchdemo.webmagic;

import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;

public class SeleniumDemo {
	public static void main(String[] args) {
		//System.setProperty("webdriver.chrome.driver", "E:\\selenium\\2.23\\chromedriver.exe");
		ChromeDriverService service = null;
		WebDriver driver = null;
		try {
			service = new ChromeDriverService.Builder().usingDriverExecutable(new File("E:\\software\\selenium\\2.29\\chromedriver.exe")).usingAnyFreePort().build();
			service.start();
			driver = new ChromeDriver(service);
			driver.manage().window().maximize();
			String siteurl = "https://search.jd.com/Search?keyword=%E5%8F%A3%E7%BD%A9&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&offset=2&page=1&s=1&click=0";
			driver.get(siteurl);
			Thread.sleep(10000);
			
			//String setscroll = "document.documentElement.scrollTop=" + 500; 
            JavascriptExecutor jse=(JavascriptExecutor) driver;  
            jse.executeScript("window.scrollBy(0, 5500)");//如何滚动窗口
            
            WebElement e1 = driver.findElement(By.id("J_bottomPage"));
            if(e1!=null){
            	System.out.println(e1.getText());
            }
			Thread.sleep(10000);
			//driver.quit();
			// 关闭 ChromeDriver 接口
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(driver!=null)
				driver.close();
			if(service!=null)
				service.stop();
		}
	}
}
